const { yearBudgetModel } = require("../models");

exports.create = async (req, res, next) => {
  try {
    const addOne = new yearBudgetModel(req.body);
    const ret = await addOne.save();
    res.status(200).json({
      data: ret,
    });
  } catch (err) {
    next(err);
  }
};
// 获取Tabel
exports.getAll = async (req, res, next) => {
    try {
      const allList = await yearBudgetModel.find();
      res.status(200).json(allList);
    } catch (err) {
      next(err);
    }
  };
// 获取详情列表
exports.get = async (req, res, next) => {
    try {
      const allList = await yearBudgetModel.findOne(req.query);
      res.status(200).json(allList);
    } catch (err) {
      next(err);
    }
  };
  // 更新
exports.patch = async (req, res, next) => {
    try {
      const allList = await yearBudgetModel.findOne(req.query);
      res.status(200).json(allList);
    } catch (err) {
      next(err);
    }
  };
  // 删除
  exports.delete = async (req, res, next) => {
    try {
      const ret = await yearBudgetModel.findOneAndDelete({_id:req.body.id})
      res.status(200).json({
        data: ret,
      });
    } catch (err) {
      next(err);
    }
  };